package com.yunhe.rentcars.pro.controller.Client;
import com.yunhe.rentcars.commons.dto.JSONResponse;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.entity.client.BacList;
import com.yunhe.rentcars.pro.service.client.BlackListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * Created by Administrator on 2017/11/24 0024.
 */
@Controller
@RequestMapping("/blackList")
public class BlackListController {
    @Autowired
    private BlackListService blackListService;
    @RequestMapping
    public String blackList(){
        return "/client/blackList/list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Pageable findPage(Integer offset, Integer limit){
        Pageable<BacList> page = blackListService.findPage(offset, limit);
        return page;
    }
    @RequestMapping("/searchData")
    @ResponseBody
    public Pageable findSearchList(String mobile,String name, String idCard){
        Pageable<BacList> searchList = blackListService.findSearchList(mobile, name, idCard);
        return searchList;
    }
    @RequestMapping("/add")
    public String save() {
        return "/client/blackList/add";
    }

    @RequestMapping("/save")
    public String save(BacList bacList){
        blackListService.save(bacList);
        return "/client/blackList/list";
    }
    @RequestMapping("/find")
    public ModelAndView edit(Long bId){
        BacList bacList = blackListService.find(bId);
        //只给这个界面传
        ModelAndView modelAndView=new ModelAndView("/client/blackList/edit");
        modelAndView.addObject("bacList",bacList);
        return modelAndView;
    }
    @RequestMapping("/update")
    public String update(BacList bacList){
        blackListService.update(bacList);
        return "/client/blackList/list";
    }
    @RequestMapping("/del")
    @ResponseBody
    public JSONResponse del(String[] ids){
        blackListService.delBatch(ids);
        return JSONResponse.success("删除成功");
    }
}
